<?php

namespace App\Admin\Controllers\Mental;

use App\Admin\Repositories\Mental\Lists;
use App\Admin\Repositories\Mental\Type;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class MentalController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Lists(['type']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('type.name','类型')->filter();
            $grid->column('title');
            $grid->column('desc');
            $grid->column('cover')->image('',100,100);
            $grid->column('price');
            $grid->column('num');
            $grid->column('is_recommend')->switch();
            $grid->column('order')->editable();
            $grid->column('created_at');
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->append('<a href="/admin/mental/topic?list_id='. $actions->row->id.'"><i class="fa fa-volume-down"></i>编辑题目</a>');
            });
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Lists(), function (Show $show) {
            $show->field('id');
            $show->field('type_id');
            $show->field('title');
            $show->field('desc');
            $show->field('cover');
            $show->field('price');
            $show->field('num');
            $show->field('is_recommend');
            $show->field('order');
            $show->field('created_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Lists(), function (Form $form) {
            $form->display('id');
            $form->select('type_id')->options((new Type())->getOptions());
            $form->text('title');
            $form->text('desc');
            $form->image('cover');
            $form->text('price');
            $form->text('num');
            $form->switch('is_recommend');
            $form->text('order');
        });
    }
}
